package org.xiaojinlong.reading;

import org.jetbrains.annotations.NotNull;

import java.lang.annotation.ElementType;
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
import java.lang.annotation.Target;
import java.lang.reflect.Method;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;

/**
 * Created by jinlong on 2015/3/11.
 */
public class Play {
    @UseCase(id = 3, description = "main")
    public static void main(String[] args) {
//        List<?> objects;
//        List<Integer> integers = new ArrayList<>();
//        Collections.addAll(integers, 1, 2, 3, 4, 5, 6);
//        objects = integers;
//        for (Object i: objects)
//            System.out1.println(i);

//        for (Method m: Play.class.getDeclaredMethods()) {
//            UseCase uc = m.getAnnotation(UseCase.class);
//            if (uc != null)
//                System.out1.println("Found Use Case:" + uc.id());
//        }

        String s = "  k  k  k  ";
        char[] chars = s.toCharArray();
        int k = 0;
        boolean lastNotBlank = false;
        outer: for (int i = 0; i < chars.length; i++) {
            if (lastNotBlank && chars[i] == ' ') {
                while (chars[i] == ' ') {
                    if (++i < chars.length) continue;
                    else break outer;
                }
                chars[k++] = ' ';
            }
            if (chars[i] != ' ') {
                chars[k++] = chars[i];
                lastNotBlank = true;
            }
        }
        System.out.println(new String(chars, 0, k));

    }

    @UseCase(id = 2) void play(@NotNull String ball) {
        System.out.println(ball);
    }

    Integer say(Integer i) {
        return i;
    }

    void Vdd() {
        throw new NullPointerException();
    }
}

@Target(ElementType.METHOD)
@Retention(RetentionPolicy.RUNTIME)
@interface Test {}

@Target(ElementType.METHOD)
@Retention(RetentionPolicy.RUNTIME)
@interface UseCase {
    int id();
    String description() default "no description";
}
